package com.adulcimer.core.config;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Simon
 * @create 2025/8/5
 * @Description
 **/
@Configuration
public class TomcatWebSocketConfig {

    @Bean
    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> webServerFactoryCustomizer() {
        return factory -> {
            factory.addContextCustomizers(context -> {
                // 设置 Tomcat WebSocket 容器的 maxSessionIdleTimeout
                context.getServletContext().setAttribute(
                        "org.apache.tomcat.websocket.DEFAULT_IDLE_TIMEOUT",
                        1800000L // 30分钟，单位毫秒
                );
            });
        };
    }
}